<!-- 推荐页组件 -->

<template>
  <div class="my-recommend"
       v-if="recommends">
    <scroll ref="scroll"
            class="recommend-content">
      <div>
        <div v-if="recommends.length"
             class="slider-wrapper">
          <my-slider>
            <div v-for="item in recommends"
                 :key="item.id">
              <a :href="item.linkUrl">
                <img :src="item.picUrl"
                     @load="loadImage"
                     class="needsclick">
              </a>
            </div>
          </my-slider>
        </div>
        <div class="recommend-list">
          <h1 class="list-title">热门歌单推荐</h1>
          <ul>
            <li v-for="item in lists.list"
                :key="item.dissid"
                class="item">
              <div class="icon">
                <img v-lazy="item.imgurl"
                     width="60"
                     height="60">
              </div>
              <div class="text">
                <p v-html="item.creator.name"
                   class="name"></p>
                <p v-html="item.dissname"
                   class="desc"></p>
              </div>
            </li>
          </ul>
        </div>
      </div>
      <!-- loading 组件 -->
      <div v-show="lists.length==0"
           class="loading-container">
        <loading></loading>
      </div>
    </scroll>
  </div>

</template>

<script>
import Scroll from "base/scroll/scroll"
import MySlider from "base/slider/slider"
import Loading from "base/loading/loading"
import { getRecommend, getDiscList } from '@/api/recommend.js'
import { ERR_OK } from '@/api/config.js'

export default {
  data () {
    return {
      recommends: [],
      lists: []
    }
  },
  created () {
    this._getRecommend();
    this._getDiscList();
  },
  methods: {
    async _getRecommend () {
      let res = await getRecommend();
      if (res.code == ERR_OK) {
        this.recommends = res.data.slider;

      }
    },
    async _getDiscList () {
      let res = await getDiscList();
      if (res.code == ERR_OK) {
        this.lists = res.data;
      }
    },
    loadImage () {
      if (!this.checkLoaded) {
        this.$refs.scroll.refresh();
        this.checkLoaded = true;
      }
    },
  },
  components: {
    MySlider,
    Scroll,
    Loading,
  }
}
</script>

<style lang="scss" scoped>
@import '~@/common/scss/mymixin.scss';

.my-recommend {
  position: fixed;
  width: 100%;
  top: 176px;
  bottom: 0;
  .recommend-content {
    height: 100%;
    overflow: hidden;
    .slider-wrapper {
      position: relative;
      width: 100%;
      overflow: hidden;
    }
    .recommend-list {
      .list-title {
        height: 130px;
        line-height: 130px;
        text-align: center;
        @include font-size($font-size-medium);
        color: $color-theme;
      }
      .item {
        display: flex;
        align-items: center;
        box-sizing: border-box;
        padding: 0 40px 40px 40px;
        .icon {
          flex: 0 0 120px;
          width: 120px;
          padding-right: 40px;
        }
        .text {
          display: flex;
          flex-direction: column;
          justify-content: center;
          flex: 1;
          line-height: 40px;
          overflow: hidden;
          font-size: $font-size-medium;
          .name {
            margin-bottom: 40px;
            color: $color-text;
          }
          .desc {
            color: $color-text-d;
          }
        }
      }
    }
    .loading-container {
      position: absolute;
      width: 100%;
      top: 50%;
      transform: translateY(-50%);
    }
  }
}
</style>
